clear all


use "$root\data\use.dta", replace


capture erase "$root/results_replication/appendix_tables/tab_a5_price.xls"
capture erase "$root/results_replication/appendix_tables/tab_a5_price.txt"

xtset fips year
//drop *38c*

**# With current price
foreach crop in corn soybeans {
	local c_name = strproper("`crop'")

	preserve
	local c = cond("`crop'" == "corn", "c", "s")
	rename `c'_d*_* d*_*
	rename `c'_tot_* tot_*
	rename `c'_pdsi_w_* pdsi_w_*
	rename `c'_pmdi_w_* pmdi_w_*
	rename `c'_tbin*_* tbin*_*
	rename `c'_prec_* prec_*
	rename `crop'_production00 production00
	replace `crop'_price=log(`crop'_price)

**## Planned planting acres
	reghdfe ln`crop'_pplanted d*_b d*_p pdsi_w_b tbin*b pdsi_w_p tbin*p `crop'_price if irrigated_ratio<0.1 & N_year_`crop'>10 & lng>-100, absorb(fips i.state#c.year i.state#c.year2 i.year) vce(cluster fips stateyear)
	estimate store `crop'_pplanted_p

**## Planting ratio	
	reghdfe `crop'_plratio d*_b d*_p pdsi_w_b tbin*b pdsi_w_p tbin*p `crop'_price if irrigated_ratio<0.1 & N_year_`crop'>10 & lng>-100, absorb(fips i.state#c.year i.state#c.year2 i.year) vce(cluster fips stateyear)
	estimate store `crop'_plratio_p

**## Harvest ratio
	reghdfe `crop'_hratio d*_b d*_p d*_g pdsi_w_b tbin*b pdsi_w_p tbin*p pdsi_w_g tbin*g `crop'_price if irrigated_ratio<0.1 & N_year_`crop'>10 & lng>-100, absorb(fips i.state#c.year i.state#c.year2 i.year) vce(cluster fips stateyear)
	estimate store `crop'_hratio_p

**## Yield
	reghdfe ln`crop'_yield d*_b d*_p d*_g pdsi_w_b tbin*b pdsi_w_p tbin*p pdsi_w_g tbin*g `crop'_price if irrigated_ratio<0.1 & N_year_`crop'>10 & lng>-100, absorb(fips i.state#c.year i.state#c.year2 i.year) vce(cluster fips stateyear)
	estimate store `crop'_yield_p

**## Production
	reghdfe ln`crop'_production d*_b d*_p d*_g pdsi_w_b tbin*b pdsi_w_p tbin*p pdsi_w_g tbin*g `crop'_price if irrigated_ratio<0.1 & N_year_`crop'>10 & lng>-100, absorb(fips i.state#c.year i.state#c.year2 i.year) vce(cluster fips stateyear)
	estimate store `crop'_production_p


* Output tables to see the numbers
	outreg2 [`crop'_pplanted] using "$root/results_replication/appendix_tables/tab_a5_price.xls", excel bdec(4) sdec(4) keep(d* *price) nocon adjr2
	outreg2 [`crop'_plratio] using "$root/results_replication/appendix_tables/tab_a5_price.xls", excel bdec(4) sdec(4) keep(d* *price) nocon adjr2
	outreg2 [`crop'_hratio] using "$root/results_replication/appendix_tables/tab_a5_price.xls", excel bdec(4) sdec(4) keep(d* *price) nocon adjr2
	outreg2 [`crop'_yield] using "$root/results_replication/appendix_tables/tab_a5_price.xls", excel bdec(4) sdec(4) keep(d* *price) nocon adjr2
	outreg2 [`crop'_production] using "$root/results_replication/appendix_tables/tab_a5_price.xls", excel bdec(4) sdec(4) keep(d* *price) nocon adjr2

restore
}

